<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@page import="com.xnx3.j2ee.Global" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@page import="com.xnx3.wangmarket.admin.G" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>

<jsp:include page="../iw/common/head.jsp">
    <jsp:param name="title" value="修改网站基本信息"/>
</jsp:include>

<html>
<head>
    <title>网站基本设置</title>
</head>
<body>

<style>
    span {
        font-size: 14px;
        /*text-align: left;*/
    }

    li {
        list-style-type: none;
        margin-top: 20px;
        text-align: right;
    }

    input {
        width: 400px;
        height: 40px;
    }

    #btn {
        display: inline-block;
        height: 38px;
        line-height: 38px;
        padding: 0 18px;
        background-color: #28a44d;
        color: #fff;
        white-space: nowrap;
        text-align: center;
        font-size: 14px;
        border: none;
        border-radius: 2px;
        cursor: pointer;
        margin-left: 60%;
        width: 200px;
        margin-top: 50px;
    }
    .layui-btn {
        background-color: #28a44d;
    }
</style>
<div style="width: 100%;height: 100%;float: left" >
        <div style="width: 40%;float: left;margin-top: 50px">
            <ul style="margin-top: 5%">
                <li>
                    <input type="hidden" id="siteId" value="${site.id}">
                    <span>网站标题：</span>
                    <input type="text" id="name" placeholder="请输入网站名称" value="${site.name}">
                </li>
                <li>
                    <span>绑定域名：</span>
                    <input type="text" id="bindDomain" placeholder="请输入网站域名" value="${site.bindDomain }">
                </li>
                <li>
                    <span>联系人姓名：</span>
                    <input type="text" id="username" placeholder="请输入联系人姓名" value="${site.username }">
                </li>
                <li>
                    <span>联系电话：</span>
                    <input type="text" id="phone" placeholder="请输入联系人电话" value="${site.phone }">
                </li>
                <li>
                    <span>咨询热线：</span>
                    <input type="text" id="hotLine" placeholder="请输入咨询热线" value="${site.hotLine }">
                </li>
            </ul>
        </div>
        <div style="float: left;margin-top: 60px;width: 50%;">
            <ul>
                <li>
                    <span>联系QQ：</span>
                    <input type="text" id="qq" placeholder="请输入联系QQ" value="${site.qq }">
                </li>
                <li>
                    <span>公司(团体)名：</span>
                    <input type="text" id="companyName" placeholder="请输入公司（团体）名" value="${site.companyName }">
                </li>
                <li>
                    <span>办公地址：</span>
                    <input type="text" id="address" placeholder="请输入办公地址" value="${site.address }">
                </li>
                <li>
                    <span>企业邮箱：</span>
                    <input type="text" id="companyEmail" placeholder="请输入企业邮箱" value="${site.companyEmail }">
                </li>
                <div style="width: 467px;margin-left: 150px;margin-top: 10px;float: right">
                    <span>企业log：</span>
                    <c:if test="${!empty site.logo}">
                        <img src='<%=basePath%>${site.logo } ' alt='' id='img'
                             style="width: 150px;height: 50px;margin-top: 20px;"/>
                    </c:if>
                    <c:if test="${empty site.logo}">
                        <img src=' ' alt='' id='img'
                             style="width: 150px;height: 50px;margin-top: 20px;"/>
                    </c:if>
                    <input type="file" id="file" style="width: 70px;margin-left: 20px;">
                </div>
            </ul>
    </div>
</div>
<div style="width: 100%;">
    <button id="btn" class="layui-btn" onclick="save()" style="margin-left: 40%">保存修改</button>
</div>
</body>
<script>

    $("#file").change(function () {
        getUpload()
    })

    function getUpload() {
        var formData = new FormData();
        formData.append('file', $('#file')[0].files[0]);
        $.ajax({
            url: '<%=basePath %>site/uploadImageLogo.do',
            type: 'POST',
            dataType: "json",
            cache: false,
            data: formData,
            processData: false,
            contentType: false
        }).done(function (res) {
            res.result == 1 ? layer.msg('上传成功', {shade: 0.3}) : layer.msg('请选择图片', {icon: 0, shade: 0.3});
            document.getElementById("img").src = '<%=basePath%>' + res.path;
        }).fail(function (res) {
            console("失败");
        });
    }

    function save() {

        var _data = {

            name: $('#name').val(),
            bindDomain: $('#bindDomain').val(),
            username: $('#username').val(),
            phone: $('#phone').val(),
            hotLine: $('#hotLine').val(),
            qq: $('#qq').val(),
            companyName: $('#companyName').val(),
            address: $('#address').val(),
            companyEmail: $('#companyEmail').val()
        }

        $.ajax({
            url: '<%=basePath %>site/savePopupSiteUpdate.do',
            type: 'post',
            dataType: "json",
            data: _data,
            success: function (result) {

                if (result.result == 1) {
                    parent.layer.msg('操作成功', {shade: 0.3});
                } else if (result.result == 0) {
                    parent.layer.msg(result.info, {shade: 0.3})
                } else {
                    parent.layer.msg(result, {shade: 0.3})
                }
            }
        }, "text")
        return false;
    };
</script>
</html>
